package io.renren.modules.frt.controller;

import java.util.Arrays;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.mapper.EntityWrapper;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.frt.entity.FamilyReport5Entity;
import io.renren.modules.frt.service.FamilyReport5Service;
import io.renren.modules.frt.service.TaskUserService;



/**
 * 表5：家庭林场调查表
 *
 * @author qibing.huang
 * @email abingtech@163.com
 * @date 2018-11-25 10:25:33
 */
@RestController
@RequestMapping("frt/familyreport5")
public class FamilyReport5Controller {
    @Autowired
    private FamilyReport5Service familyReport5Service;
    @Autowired
    private TaskUserService taskUserService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("frt:familyreport5:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = familyReport5Service.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{taskUserId}")
    public R info(@PathVariable("taskUserId") Long taskUserId){
        FamilyReport5Entity familyReport5 = familyReport5Service.selectOne(new EntityWrapper<FamilyReport5Entity>().eq("task_user_id", taskUserId));

        return R.ok().put("familyreport5", familyReport5==null?new FamilyReport5Entity(): familyReport5);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody FamilyReport5Entity familyReport5){
    	
    	if(familyReport5.getTaskUserId() == null) {
    		return R.error("task_user_id["+familyReport5.getTaskUserId()+"]参数错误");
    	}
    	
    	familyReport5Service.insert(familyReport5);
		
		taskUserService.onlineCallbackTaskUser(familyReport5.getTaskUserId(), familyReport5.getReportId());
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody FamilyReport5Entity familyReport5){
		familyReport5Service.updateById(familyReport5);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("frt:familyreport5:delete")
    public R delete(@RequestBody Long[] reportIds){
		familyReport5Service.deleteBatchIds(Arrays.asList(reportIds));

        return R.ok();
    }
    
}
